import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param nums int整型一维数组
     * @return int整型
     */
    public static int count = 0;
    public int InversePairs (int[] nums) {
        // write code here
        merge(nums, 0, nums.length-1);
        return count;
    }
    public void merge(int[] nums, int left,int right){
        if(left >= right){
            return;
        }
        int mid = (left + right) / 2;
        merge(nums, left ,mid);
        merge(nums,mid + 1,right);
        sort(nums, left, mid,right);

    }
    public void sort(int[] nums, int left,int mid,  int right){
        int i = left;
        int j = mid + 1;
        int t = 0;
        int[] tmp = new int[nums.length];
        while(i <= mid && j <= right){
            if(nums[i] <= nums[j]){
                tmp[t++] = nums[i++];
            }else{
                tmp[t++] = nums[j++];
                count += (mid - i + 1);
                count %= 1000000007;
            }
        }
        while(i <= mid){
            tmp[t++] = nums[i++];
        }
        while(j <= right){
            tmp[t++] = nums[j++];
        }
        i = left;
        j = 0;
        for(;i<=right;i++){
            nums[i] = tmp[j++];
        }
    }
}